/*
 * @Author: TuYongTao
 * @Date: 2021-10-29 18:13:43
 * @LastEditors: your Name
 * @LastEditTime: 2021-10-29 18:37:52
 * @Description: 
 */
import Observer from './observer.js'
class Vue {
  constructor(options = {}) {
    
    this.$options = options
    this.$el = typeof options.el === 'string' ? document.querySelector(options.el) : options.el
    this.$data = options.data || {}
    this.proxy(this.$data)
    new Observer(this.$data)
  }

  proxy(data) {
    Object.keys(data).forEach((key)=>{
      Object.defineProperty(this, key, {
        enumerable: true,
        configurable: true,
        get() {
          return this.$data[key]
        },
        set(newVal) {
          if(newVal === this.$data[key]) {
            return 
          }
          this.$data[key] = newVal
        }
      })
    })
  }
}
